﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;
using System.Collections.Generic;

public partial class common : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {   
            TarreOA.TarreOAModels.User u = (User)Session["user"];
            List<Popedom> n1 = new List<Popedom>();
            List<Popedom> n2 = new List<Popedom>();
            List<Popedom> n3 = new List<Popedom>();

            if (u.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in u.PopedomGroup.PopedomList)
                {
                    if (var.Level == 1)
                    {
                        n1.Add(var);
                    }
                    else if (var.Level == 2)
                    {
                        n2.Add(var);
                    }
                    else if (var.Level == 3)
                    {
                        n3.Add(var);
                    }
                }
            }
            TreeNode tn = new TreeNode("全部展开");
            tn.SelectAction = TreeNodeSelectAction.Expand;
            TreeView1.Nodes.Add(tn);
            foreach (Popedom var in n1)
            {
                TreeNode tn1 = new TreeNode(var.PopedomName);
                tn1.SelectAction = TreeNodeSelectAction.Expand;
                tn1.ImageUrl = "images/menu/" + var.ImagePath + ".gif";
                //tn1.Target = "s1";
                //tn1.NavigateUrl = var.Url;
                tn.ChildNodes.Add(tn1);
                foreach (Popedom p2 in n2)
                {
                    if (p2.BaseNode == var.PopedomId)
                    {
                        TreeNode tn2 = new TreeNode(p2.PopedomName);
                        tn2.ImageUrl = @"images/menu/" + p2.ImagePath + ".gif";
                        if (p2.Url != null && p2.Url !="")
                        {
                            tn2.Target = "s1";
                            tn2.NavigateUrl = p2.Url;
                        }
                        else
                        {
                            tn2.SelectAction = TreeNodeSelectAction.Expand;
                        }
                        tn1.ChildNodes.Add(tn2);
                        foreach (Popedom p3 in n3)
                        {
                            if (p3.BaseNode == p2.PopedomId)
                            {
                                TreeNode tn3 = new TreeNode(p3.PopedomName);
                                tn3.ImageUrl = @"images/menu/" + p3.ImagePath + ".gif";
                                tn3.Target = "s1";
                                tn3.NavigateUrl = p3.Url;
                                tn2.ChildNodes.Add(tn3);
                            }
                        }
                    }
                }
            }
            TreeView1.CollapseAll();
            TreeView1.Nodes[0].Expand();
        }
    }
}
